package com.leetcode.LC;

public class LC1736 {
    public String maximumTime(String time) {

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < time.length(); i++) {
            if (time.charAt(i) == '?') {
                if (i == 0) {
                    if (time.charAt(i + 1) < '4' || time.charAt(i + 1) == '?') {
                        builder.append('2');
                    } else {
                        builder.append('1');
                    }
                } else if (i == 1) {
                    if (builder.toString().charAt(i - 1) != '2') {
                        builder.append('9');
                    } else {
                        builder.append('3');
                    }
                } else if (i == 3) {
                    builder.append('5');
                } else if (i == 4) {
                    builder.append('9');
                }
            } else {
                builder.append(time.charAt(i));
            }
        }
        return builder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new LC1736().maximumTime("??:3?"));
    }
}
